$(function () {
    function getHighChart(strategyId) {
        var _timestamp = new Date().getTime();
        var _secret = hex_md5(ip + '/Back/Strategy/StrategyJQProfitDetail?timestamp=' + _timestamp + salt);
        $.ajax({
            type: "POST",
            url: ip + '/Back/Strategy/StrategyJQProfitDetail?timestamp=' + _timestamp + '&secret=' + _secret + '&token=' + _token,
            dataType: 'json',
            headers: {
                "Content-Type": "application/json",
                "Accept": "application/json;charset=utf-8",
                'token': _token
            },
            data: JSON.stringify({
                "strategyId": parseInt(_urlStrategyId),
            }),
            xhrFields: {withCredentials: true},
            success: function (data) {
                console.log(data);
                var result = JSON.stringify(data);
                if (data.code == 1) {
                    var baseProfitArr = []; //(number, optional): 基准收益率 ,
                    var  dateKeyStrArr = []; //(string, optional): 日期字符串 ,
                    var   profitValueArr =[];//(number, optional): 收益额 ,
                    var   strategyProfitArr=[];//(number, optional): 策略收益率 ,
                    var   tradeValueArr =[];//(number, optional): 交易额
                    var _totalReturnsPer = data.data.totalReturnsPer;// (number, optional): 策略收益 ,
                    var _totalAnnualizedReturnsPer = data.data.totalAnnualizedReturnsPer; //(number, optional): 策略年化收益 ,
                    var _baseTotalReturnsPer = data.data.baseTotalReturnsPer; //(number, optional): 基准收益 ,
                    var _alpha = data.data.alpha ;//(number, optional): alpha ,
                    var _beta = data.data.beta;// (number, optional): beta ,
                    var _sharpe = data.data.sharpe ;//(number, optional): sharpe ,
                    var _winProbability = data.data.winProbability;// (number, optional): 胜率
                    var _profitRatio = data.data.profitRatio; //(number, optional): 盈亏比 ,
                    var _maxDrawdown = data.data.maxDrawdown; //(number, optional): 最大回撤 ,
                    var tr = "<tr><td>" + _totalReturnsPer + "</td><td>" + _totalAnnualizedReturnsPer + "</td><td>" + _baseTotalReturnsPer + "</td><td>" + _alpha + "</td><td>" + _beta + "</td><td>" + _sharpe + "</td><td>" + _winProbability + "</td><td>" + _profitRatio + "</td><td>" + _maxDrawdown + "</td></tr>";
                    $("#profitTable tbody tr").remove();
                    $("#profitTable tbody").append(tr);
                    var count = data.data.strategyDailyDetailModels.length;
                    for (let i = 0; i < count; i++) {
                        var _baseProfit = data.data.strategyDailyDetailModels[i].baseProfit;//(number, optional): 基准收益率 ,
                        var _dateKeyStr = data.data.strategyDailyDetailModels[i].dateKeyStr; //(string, optional): 日期字符串 ,
                        var _profitValue = data.data.strategyDailyDetailModels[i].profitValue;// (number, optional): 收益额 ,
                        var _strategyProfit = data.data.strategyDailyDetailModels[i].strategyProfit; //(number, optional): 策略收益率 ,
                        var _tradeValue = data.data.strategyDailyDetailModels[i].tradeValue //(number, optional): 交易额
                        baseProfitArr.push(_baseProfit);
                        dateKeyStrArr.push(_dateKeyStr);
                        profitValueArr.push(_profitValue);
                        strategyProfitArr.push(_strategyProfit);
                        tradeValueArr.push(_tradeValue);

                    }
                    //策略收益率图
                    var profit100Chart = Highcharts.chart('profit100Chart', {
                        title: {
                            text:'策略收益率图'
                        },
                        credits: {
                            text: ''
                        },
                        xAxis: {
                            categories: dateKeyStrArr,
                        },
                        yAxis: {
                            title: {
                                text: '收益率'
                            }
                        },
                        series: [{
                            data: baseProfitArr,
                            name: '基准收益率'
                        }, {
                            data: strategyProfitArr,
                            name: '策略收益率'
                        }]
                    });

                    // //每日盈亏图
                    var profitChart = Highcharts.chart('profitChart',{
                        chart: {
                            type: 'column'
                        },
                        title: {
                            text: '每日盈亏'
                        },
                        xAxis: {
                            categories: dateKeyStrArr,
                            text:'x轴标题'

                        },
                        yAxis: {
                            title: {
                                text: '盈亏额'
                            }
                        },
                        credits: {
                            text: ''
                        },
                        series: [{
                            name: '每日盈亏额',
                            data: profitValueArr
                        }]
                    });
                    //每日买卖图
                    var transactionChart = Highcharts.chart('transactionChart',{
                        chart: {
                            type: 'column'
                        },
                        title: {
                            text: '交易量'
                        },
                        xAxis: {
                            categories: dateKeyStrArr
                        },
                        yAxis: {
                            title: {
                                text: '交易量'
                            }
                        },
                        credits: {
                            text: ''
                        },
                        series: [{
                            name: '每日交易量',
                            data: tradeValueArr
                        }]
                    });

                }
            },
            error: function () {
                alert('请求失败');
            }
        });
    }

    getHighChart()
})

